
import logging
import time
from binance.lib.utils import config_logging
from binance.websocket.spot.websocket_api import SpotWebsocketAPIClient
from examples.utils.prepare_env import get_api_key


config_logging(logging, logging.DEBUG)


def on_close(_):
    logging.info("Do custom stuff when connection is closed")


def message_handler(_, message):
    logging.info(message)


my_client = SpotWebsocketAPIClient(
    stream_url="wss://ws-api.binance.com:443/ws-api/v3",
    api_key="3S4j9rBxss0KBivifkgMMEykgWad9GEMl9hdgMhViiwKGNDy5NoLkYHIDg6K3VU5",
    api_secret="NzWj2BnVToddcO39tkJp7N1Xz041EYwzgVibMV7czf0ZaHWfuCM8GHnO8pBp03xH",
    on_message=message_handler,
    on_close=on_close,
)


accout11 = my_client.account()

time.sleep(2)

logging.info("closing ws connection")
my_client.stop()